package com.baogu.factoryjob.service.impl;

import com.baogu.factoryjob.manager.SysLogManager;
import com.baogu.factoryjob.service.SysLogService;
import com.baogu.factoryjob.util.DateUtils;
import com.baogu.factoryjob.util.UuidUtil;
import com.baogu.model.job.SysLog;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SysLogServiceImpl implements SysLogService {

    private Logger logger = LogManager.getLogger(getClass());

    @Autowired
    SysLogManager sysLogManager;

    @Override
    public Integer addSysLog(SysLog sysLog) {
        sysLog.setId(UuidUtil.get32UUID());
        sysLog.setEndtime(DateUtils.now(DateUtils.yyyyMMddHHmmssSSS()));
        if(sysLog.getException() != null){
            logger.error(sysLog.getException());
        }
        return sysLogManager.addSysLog(sysLog);
    }
}
